console.log("xxxxxxxxxxxxxxxxxxxx","队列（Deque.js）测试","xxxxxxxxxxxxxxxxxxxxxxxxxx")


let result ='';

// 队列

function testArrayDeque(){
    let deque = new ArrayDeque();
    console.log("==========","ArrayDeque.push 测试","==========")
    deque.push('A');
    let result = eq(1,deque.size);
    testPrint(result,"入队")
    deque.push('B');
    result = eq(2,deque.size);
    testPrint(result,"入队")
    deque.push('C');
    result = eq(3,deque.size);
    testPrint(result,"入队")

    console.log("==========","ArrayDeque.toArray 测试","==========")
    let ex = ['A','B','C'];
    let arr = deque.toArray();
    result = eqArray(ex, arr)
    testPrint(result, "队列转数组")

    console.log("==========","ArrayDeque.peek 测试","==========")
    let ele = deque.peek();
    result = eq('A',ele);
    testPrint(result,"访问队首元素")

    console.log("==========","ArrayDeque.pop 测试","==========")
    ele = deque.pop();
    result = eq('A',ele) && eq(2,deque.size)
    testPrint(result,"出队")

    ele = deque.pop();
    result = eq('B',ele) && eq(1,deque.size)
    testPrint(result,"出队")

    ele = deque.pop();
    result = eq('C',ele) && eq(0,deque.size)
    testPrint(result,"出队")

    try {
        ele = deque.pop();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"出队异常")
    }

    console.log("==========","ArrayDeque.peek 测试","==========")
    try {
        ele = deque.peek();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"访问队首元素")
    }
}

testArrayDeque();



function testFixArrayDeque(){
    let deque = new FixArrayDeque(3);
    console.log("==========","FixArrayDeque.push 测试","==========")
    deque.push('A');
    let result = eq(1,deque.size);
    testPrint(result,"入队")
    deque.push('B');
    result = eq(2,deque.size);
    testPrint(result,"入队")
    deque.push('C');
    result = eq(3,deque.size);
    testPrint(result,"入队")

    try {
        ele = deque.push('D');
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"入队异常")
    }

    console.log("==========","FixArrayDeque.toArray 测试","==========")
    let ex = ['A','B','C'];
    let arr = deque.toArray();
    result = eqArray(ex, arr)
    testPrint(result, "队列转数组")

    console.log("==========","FixArrayDeque.peek 测试","==========")
    let ele = deque.peek();
    result = eq('A',ele);
    testPrint(result,"访问队首元素")

    console.log("==========","FixArrayDeque.pop 测试","==========")
    ele = deque.pop();
    result = eq('A',ele) && eq(2,deque.size)
    testPrint(result,"出队")

    ele = deque.pop();
    result = eq('B',ele) && eq(1,deque.size)
    testPrint(result,"出队")

    ele = deque.pop();
    result = eq('C',ele) && eq(0,deque.size)
    testPrint(result,"出队")

    try {
        ele = deque.pop();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"出队异常")
    }

    console.log("==========","FixArrayDeque.peek 测试","==========")
    try {
        ele = deque.peek();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"访问队首元素")
    }
}

testFixArrayDeque();

function testFixArrayDequeCase2() {
    let deque = new FixArrayDeque(3);
    deque.push('A');
    deque.push('B');
    deque.push('C');

    deque.pop();
    deque.pop();

    console.log("==========","FixArrayDeque.push 测试","==========")
    
    deque.push('D');
    let result = eq(2,deque.size);
    testPrint(result,"入队")
    deque.push('E');
    result = eq(3,deque.size);
    testPrint(result,"入队")
    
    console.log("==========","FixArrayDeque.toArray 测试","==========")
    let ex = ['C','D','E'];
    let arr = deque.toArray();
    result = eqArray(ex, arr)
    testPrint(result, "队列转数组")
}

testFixArrayDequeCase2();

function testLinkedDequeCase1(){
    let deque = new LinkedDeque();

    console.log("==========","LinkedDeque.push 测试","==========")
    deque.push('A');
    let result = eq(1,deque.size);
    testPrint(result,"入队")
    deque.push('B');
    result = eq(2,deque.size);
    testPrint(result,"入队")
    deque.push('C');
    result = eq(3,deque.size);
    testPrint(result,"入队")

    console.log("==========","LinkedDeque.toArray 测试","==========")
    let ex = ['A','B','C'];
    let arr = deque.toArray();
    result = eqArray(ex, arr)
    testPrint(result, "队列转数组")

    console.log("==========","LinkedDeque.peek 测试","==========")
    let ele = deque.peek();
    result = eq('A',ele);
    testPrint(result,"访问队首元素")

    console.log("==========","LinkedDeque.pop 测试","==========")
    ele = deque.pop();
    result = eq('A',ele) && eq(2,deque.size)
    testPrint(result,"出队")

    ele = deque.pop();
    result = eq('B',ele) && eq(1,deque.size)
    testPrint(result,"出队")

    ele = deque.pop();
    result = eq('C',ele) && eq(0,deque.size)
    testPrint(result,"出队")

    try {
        ele = deque.pop();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"出队异常")
    }

    console.log("==========","LinkedDeque.peek 测试","==========")
    try {
        ele = deque.peek();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"访问队首元素")
    }
}

testLinkedDequeCase1();



function testDoubleLinkedQueueCase1(){
    let deque = new DoubleLinkedQueue();

    console.log("==========","DoubleLinkedQueue.pushFirst 测试","==========")
    deque.pushFirst('A');
    let result = eq(1,deque.size);
    testPrint(result,"队头入队")
    deque.pushFirst('B');
    result = eq(2,deque.size);
    testPrint(result,"队头入队")
    deque.pushFirst('C');
    result = eq(3,deque.size);
    testPrint(result,"队头入队")

    deque.pushLast('D');
    result = eq(4,deque.size);
    testPrint(result,"队尾入队")
    deque.pushLast('E');
    result = eq(5,deque.size);
    testPrint(result,"队尾入队")
    deque.pushLast('F');
    result = eq(6,deque.size);
    testPrint(result,"队尾入队")

    console.log("==========","DoubleLinkedQueue.toArray 测试","==========")
    let ex = ['C','B','A','D','E','F'];
    let arr = deque.toArray();
    result = eqArray(ex, arr)
    testPrint(result, "队列转数组")

    console.log("==========","DoubleLinkedQueue.peekFirst 测试","==========")
    let ele = deque.peekFirst();
    result = eq('C',ele);
    testPrint(result,"访问队首元素")

    console.log("==========","DoubleArrayQueue.peekLast 测试","==========")
    ele = deque.peekLast();
    result = eq('F',ele);
    testPrint(result,"访问队尾元素")

    console.log("==========","DoubleLinkedQueue.popFirst 测试","==========")
    ele = deque.popFirst();
    result = eq('C',ele) && eq(5,deque.size)
    testPrint(result,"队头出队")

    ele = deque.popFirst();
    result = eq('B',ele) && eq(4,deque.size)
    testPrint(result,"队头出队")

    ele = deque.popFirst();
    result = eq('A',ele) && eq(3,deque.size)
    testPrint(result,"队头出队")

    console.log("==========","DoubleLinkedQueue.popLast 测试","==========")
    ele = deque.popLast();
    result = eq('F',ele) && eq(2,deque.size)
    testPrint(result,"队尾出队")

    ele = deque.popLast();
    result = eq('E',ele) && eq(1,deque.size)
    testPrint(result,"队尾出队")

    ele = deque.popLast();
    result = eq('D',ele) && eq(0,deque.size)
    testPrint(result,"队尾出队")

    try {
        ele = deque.popFirst();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"出队异常")
    }

    try {
        ele = deque.popLast();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"出队异常")
    }

    console.log("==========","DoubleArrayQueue.peekFirst 测试","==========")
    try {
        ele = deque.peekFirst();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"访问队首元素")
    }

    console.log("==========","DoubleArrayQueue.peekLast 测试","==========")
    try {
        ele = deque.peekLast();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"访问队首元素")
    }
}

testDoubleLinkedQueueCase1();


function testDoubleArrayQueueCase1(){
    let deque = new DoubleArrayQueue(10);

    console.log("==========","DoubleArrayQueue.push 测试","==========")
    deque.pushFirst('A');
    let result = eq(1,deque.size);
    testPrint(result,"队头入队")
    deque.pushFirst('B');
    result = eq(2,deque.size);
    testPrint(result,"队头入队")
    deque.pushFirst('C');
    result = eq(3,deque.size);
    testPrint(result,"队头入队")

    deque.pushLast('D');
    result = eq(4,deque.size);
    testPrint(result,"队尾入队")
    deque.pushLast('E');
    result = eq(5,deque.size);
    testPrint(result,"队尾入队")
    deque.pushLast('F');
    result = eq(6,deque.size);
    testPrint(result,"队尾入队")

    console.log("==========","DoubleArrayQueue.toArray 测试","==========")
    let ex = ['C','B','A','D','E','F'];
    let arr = deque.toArray();
    result = eqArray(ex, arr)
    testPrint(result, "队列转数组")

    console.log("==========","DoubleArrayQueue.peekFirst 测试","==========")
    let ele = deque.peekFirst();
    result = eq('C',ele);
    testPrint(result,"访问队首元素")

    console.log("==========","DoubleArrayQueue.peekLast 测试","==========")
    ele = deque.peekLast();
    result = eq('F',ele);
    testPrint(result,"访问队尾元素")
    

    console.log("==========","DoubleArrayQueue.popFirst 测试","==========")
    ele = deque.popFirst();
    result = eq('C',ele) && eq(5,deque.size)
    testPrint(result,"队头出队")

    ele = deque.popFirst();
    result = eq('B',ele) && eq(4,deque.size)
    testPrint(result,"队头出队")

    ele = deque.popFirst();
    result = eq('A',ele) && eq(3,deque.size)
    testPrint(result,"队头出队")

    ele = deque.popLast();
    result = eq('F',ele) && eq(2,deque.size)
    testPrint(result,"队尾出队")

    ele = deque.popLast();
    result = eq('E',ele) && eq(1,deque.size)
    testPrint(result,"队尾出队")

    ele = deque.popLast();
    result = eq('D',ele) && eq(0,deque.size)
    testPrint(result,"队尾出队")
    

    try {
        ele = deque.popFirst();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"出队异常")
    }

    try {
        ele = deque.popLast();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"出队异常")
    }
    
    console.log("==========","DoubleArrayQueue.peekFirst 测试","==========")
    try {
        ele = deque.peekFirst();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"访问队首元素")
    }

    console.log("==========","DoubleArrayQueue.peekLast 测试","==========")
    try {
        ele = deque.peekLast();
    } catch (e) {
        result = eq(e.message, '超出队列范围')
        testPrint(result,"访问队首元素")
    }
}

testDoubleArrayQueueCase1();